/*****************************************************************************
 * Open MCT, Copyright (c) 2014-2018, United States Government
 * as represented by the Administrator of the National Aeronautics and Space
 * Administration. All rights reserved.
 *
 * Open MCT is licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 * Open MCT includes source code licensed under additional open source
 * licenses. See the Open Source Licenses file (LICENSES.md) included with
 * this source code distribution or the Licensing information page available
 * at runtime from the About dialog for additional information.
 *****************************************************************************/
.frame {
    $ohH: $btnFrameH;
    $bc: $colorInteriorBorder;

    position: absolute;

    &.child-frame.panel {
        z-index: 0; // Needed to prevent child-frame controls from showing through when another child-frame is above
        &:not(.no-frame) {
            background: $colorBodyBg;
            border-color: $bc;
        }
    }

    .object-browse-bar {
        font-size: 0.75em;
        height: $ohH;
        line-height: $ohH;
        .right {
            @include trans-prop-nice-fade($controlFadeMs);
            padding-left: $interiorMargin;
        }
    }

    &.t-object-type-timer,
    &.t-object-type-clock,
    &.t-object-type-hyperlink,
    &.t-object-type-summary-widget {
        // Hide the right side buttons for objects where they don't make sense
        // Note that this will hide the view Switcher button if applied
        // to an object that has it.
        .object-browse-bar .right { display: none; }
    }

    > .object-holder.abs {
        top: $ohH + $interiorMargin;
    }
    .contents {
        $m: $interiorMargin;
        top: $m;
        right: $m;
        bottom: $m;
        left: $m;
    }
    &.frame-template {
        .h-local-controls {
            .s-button,
            .s-menu-button {
                height: $btnFrameH;
                line-height: $btnFrameH;
                padding: 0 $interiorMargin;
                > span,
                &:before {
                    font-size: 0.65rem;
                }
            }
        }

        .s-menu-button:after {
            font-size: 8px;
        }

        .view-switcher {
            z-index: 10;
        }
    }
    .view-switcher {
        margin-right: $interiorMargin; // Kick other top bar elements away when I'm present.
        // Hide the name when the view switcher is in a frame context
        .title-label {
            display: none;
        }
    }

    &.no-frame {
        background: transparent !important;
        border-color: transparent;
        .object-browse-bar .right {
            $m: 0;
            padding: $interiorMarginSm;
            position: absolute;
            top: $m; right: $m;
            z-index: 2;
        }
        &.t-frame-outer > .t-rep-frame {
            &.contents {
                $m: 0px;
                top: $m;
                right: $m;
                bottom: $m;
                left: $m;
            }

            > .t-frame-inner {
                &.t-object-type-layout {
                    > .object-browse-bar {
                        .t-btn-view-large {
                            // When a nested layout has its frame hidden, don't display a view large button
                            display: none;
                        }
                    }
                }

                > .object-browse-bar {
                    .left {
                        display: none;
                    }
                }

                > .object-holder.abs {
                    overflow: hidden;
                    top: 0 !important;
                }
            }
        }
    }

    &.t-frame-outer .title-label.s-input-inline {
        // Prevent frame titles from being edited when nested in a Layout
        pointer-events: none !important;
    }

    /********************************************************** OBJECT TYPES */
    .t-object-type-hyperlink,
    .t-object-type-summary-widget {
        .object-holder {
            overflow: hidden;
        }
        .w-summary-widget,
        .l-summary-widget,
        .l-hyperlink.s-button {
            // Some object types expand to the full size of the object-holder.
            @extend .abs;
        }

        .l-summary-widget,
        .l-hyperlink.s-button {
            .label {
                @include ellipsize();
                transform: translateY(-50%);
                padding: 0 $interiorMargin;
                position: absolute;
                min-width: 0;
                left: 0; right: 0;
                text-align: center;
                top: 50%;
            }
        }
    }
}

body.desktop .frame {
    // Hide local controls initially and show it them on hover when they're in an element that's in a frame context
    // Frame template is used because we need to target the lowest nested frame
    .object-browse-bar .btn-bar {
        @include trans-prop-nice($props: opacity, $dur: 250ms);
        opacity: 0;
        pointer-events: none;
    }

    // Target the first descendant so that we only show the elements in the outermost container.
    // Handles the case where we have layouts in layouts.
    &:hover > .object-browse-bar {
        .btn-bar {
            @include trans-prop-nice($props: opacity, $dur: 10ms);
            opacity: 1;
            pointer-events: inherit;
        }
    }
}

.holder-object:not(.s-status-editing) {
    .l-layout {
        &.fl-column,
        &.fl-row,
        &.fl-wrap,
        &.fl-phone-best-fit,
        &.fl-mobile-best-fit {
            display: flex;
            flex-wrap: nowrap;
            align-content: stretch;
            align-items: stretch;
            > .frame {
                display: block;
                flex: 1 1 auto;
                width: auto !important;
                height: auto !important;
                &.t-object-type-summary-widget {
                    &.no-frame.t-frame-outer > .t-rep-frame {
                        &.contents {
                            // When frame is hidden, add a bit of margin to the contents
                            $m: $interiorMargin;
                            top: $m; right: $m; bottom: $m; left: $m;
                        }
                    }
                }
            }
        }
        &.fl-column {
            flex-direction: column;
            padding-right: $interiorMargin;
        }
        &.fl-row {
            flex-direction: row;
            padding-bottom: $interiorMargin;
        }

        &.fl-wrap {
            align-content: flex-start;
            align-items: flex-start;
            flex-wrap: wrap;
        }
    }
}

.holder-object {
    .l-layout {
        &.fl-column,
        &.fl-row,
        &.fl-wrap,
        &.fl-phone-best-fit,
        &.fl-mobile-best-fit {
            > .frame {
                top: auto !important;
                left: auto !important;
                position: relative;
            }
        }
    }
}

body.mobile {
    .l-layout.fl-mobile-best-fit {
        flex-wrap: wrap !important;
        padding: 0 !important;
    }
    &.portrait .l-layout.fl-mobile-best-fit {
        flex-direction: column !important;
    }
    &.landscape .l-layout.fl-mobile-best-fit {
        flex-direction: row !important;
    }
}
